package sw6.visualschedule;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.NoSuchElementException;

import android.util.Pair;

public class PictureList implements Iterable<Pair<Integer, String>>, Iterator<Pair<Integer, String>>{
	private ArrayList<Integer> ids;
	private ArrayList<String> subs;
	int count = 0;
	public PictureList()
	{
		new PictureList(new ArrayList<Integer>(), new ArrayList<String>());
	}
	public PictureList(ArrayList<Integer> ids, ArrayList<String> subs)
	{
		this.ids = ids;
		this.subs = subs;
		if(subs.size() < ids.size())
		{
			for (int i = subs.size()-1; i < ids.size()-1; i++) {
				subs.add(null);
			}
		} else if (subs.size() > ids.size()){
			for (int i = ids.size(); i < subs.size()-1; i++) {
				ids.remove(i);
			}
		}
	}
	public void add(int id)
	{
		add(id, null);
	}
	public void add(int id, String sub)
	{
			ids.add(id);
			subs.add(sub);
	}
	public Pair<Integer, String> get(int i) {
		return new Pair<Integer, String>(ids.get(i), subs.get(i));
	}
	public int size(){
		return Math.max(ids.size(), subs.size());
	}
	//Iteratable
	@Override
	public Iterator<Pair<Integer, String>> iterator() {
		return this;
	}
	
	//Iterator
	@Override
	public boolean hasNext() {
		if(count < size()) return true; 
	    return false;
	}
	@Override
		public Pair<Integer, String> next() {
		if(count == size())  
			throw new NoSuchElementException(); 
	 
	    count++; 
	    return get(count-1);
	}
	@Override
	public void remove() {
		throw new UnsupportedOperationException();
	}
}
